<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>应用管理</title>
    {include file="common/_require"}

    <script>
        var currentHeaderNavItem = 'Admin';
        var currentLeftNavItem = 'premission';
    </script>
</head>

<body class="layui-layout-body">

    <div class="layui-layout layui-layout-admin">
        {include file="common/_header"}

        {include file="common/left_admin_manage"}

        <div class="layui-body">

            <div style="padding:15px">
                <div class="main-header">
                    <span class="layui-breadcrumb">
                        <a>首页</a>
                        <a><cite>权限管理</cite></a>
                    </span>
                </div>
                <div class="main-container">
                    
                    <div>
                        <table class="layui-table">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>权限名称</th>
                                    <th>权限URL</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {volist name='list' id='vo'}
                                    
                                <tr class="item" data-id="{$vo.id}" data-is-log="{$vo->getData('is_log')}">
                                    <td>{$vo.id}</td>
                                    <td>
                                        <span>{$vo.name}</span>
                                        <div class="layui-btn layui-btn-sm set-name" data-name="{$vo.name}">设置</div>
                                    </td>
                                    <td>
                                        <span>{$vo.app}/{$vo.controller}/{$vo.action}</span>
                                        <div class="layui-btn layui-btn-sm set-url" data-url="{$vo.app}/{$vo.controller}/{$vo.action}">设置</div>
                                    </td>
                                    <td>
                                        <div class="layui-btn-container">
                                            <div class="layui-btn layui-btn-sm is-log" >{$vo.is_log}</div>
                                            <div class="layui-btn layui-btn-sm delete">删除</div>
                                        </div>
                                    </td>
                                </tr>
                                {/volist}
                               {if condition="count($list) eq 0" }
                                   <tr>
                                       <td colspan="3">暂无数据</td>
                                   </tr>
                               {/if}
                            </tbody>
                        </table>
                        <div>
                            {$list->render()|raw}
                        </div>
                    </div>
                </div>
            </div>
        </div>


        {include file="common/_footer"}

        <script>
        
            layui.use(['layer'],function(){
                $('.set-name').click(function(){
                    var item = this;
                    layer.prompt({
                        value:$(item).data('name')
                    },function(value,index){
                        $.post('{:url("AdminPermission/update")}',{
                            id:$(item).parents('tr').data('id'),
                            name:value
                        },function(result){
                            layer.close(index)
                            $(item).siblings('span').text(value)
                        })
                    })
                })
                $('.set-url').click(function(){
                    var item = this;
                    layer.prompt({
                        value:$(item).data('url')
                    },function(value,index){
                        $.post('{:url("AdminPermission/update")}',{
                            id:$(item).parents('tr').data('id'),
                            url:value
                        },function(result){
                            layer.close(index)
                            $(item).siblings('span').text(value)
                        })
                    })
                })

                $('.delete').click(function(){
                    var item = this;
                    layer.confirm('确定要删除吗?',function(){
                        $.get('{:url("AdminPermission/delete")}',{
                            id:$(item).parents('tr').data('id')
                        },function(result){
                            if(result.code == 0){
                                layer.msg('删除成功');
                                $(item).parents('tr').remove();
                            }else{
                                layer.msg(result.msg)
                            }
                        })
                    })
                })

                $('.is-log').click(function(){
                    var item = this;
                    var isLog = $(item).parents('tr').data('is-log')
                    if(isLog == 0){
                        isLog = 1
                    }else{
                        isLog = 0
                    }
                    $.post('{:url("AdminPermission/update")}',{
                        id:$(item).parents('tr').data('id'),
                        is_log:isLog
                    },function(){
                        if(isLog == 1){
                            $(item).text('记录')
                        }else{
                            $(item).text('不记录')

                        }
                    })
                })
            })
        
        </script>
    </div>
</body>

</html>